/**
 * 
 */
package com.lazyshopkeeper.front.service.impl;

import java.util.List;

import javax.annotation.PostConstruct;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.lazyshopkeeper.front.common.Constant;
import com.lazyshopkeeper.front.domain.VasInfo;
import com.lazyshopkeeper.front.persistence.SysConfigMapper;
import com.lazyshopkeeper.front.persistence.VasInfoMapper;
import com.lazyshopkeeper.front.service.IVasService;

/**
 * 系统初始化的服务类，当前初始化加载配置信息
 * @author xuyuqi
 *
 */
@Service
public class InitService {

	private static Logger logger = LoggerFactory.getLogger(InitService.class);
	@Autowired
	private SysConfigMapper sysConfigMapper;
	@Autowired
	private IVasService localVasService;
	
	@PostConstruct
	public void init(){
		logger.debug("系统初始化开始，参数加载中.......");
		// 初始化参数
		Constant.API_URL = sysConfigMapper.getSysConfig("apiUrl").getValue();
		Constant.APP_KEY = sysConfigMapper.getSysConfig("appKey").getValue();
		Constant.APP_SERCET = sysConfigMapper.getSysConfig("appSecret").getValue();
		Constant.ARTICLE_CODE = sysConfigMapper.getSysConfig("articleCode").getValue();
		Constant.LOGIN_URL = sysConfigMapper.getSysConfig("loginUrl").getValue();
		Constant.OAUTH_URL = sysConfigMapper.getSysConfig("OAuthToken").getValue();
		Constant.OAUTH_API_URL = sysConfigMapper.getSysConfig("OAuthApiUrl").getValue();
		
		List<VasInfo> vis = localVasService.getAllVasInfo();
		for (VasInfo vi : vis) {
			Constant.vasMapper.put(vi.getCode(), vi.getName());
		}
		logger.debug("系统初始化开始，参数加载完毕");
	}
}
